/**
 * 
 */
package com.wbl.client;


import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * @Description:  
 * 客户端
 * @version: v1.0.0
 * @author: wbl
 * @date: 2020年1月13日 下午1:22:29
 */
public class ClientConnect{

	public static void main(String[] args) {
		connect();
//		System.out.println("客户端启动成功！");
		

		
	}
	public static void connect(){
		
		 EventLoopGroup group = new NioEventLoopGroup();
        try {
            Bootstrap gate = new Bootstrap();
            gate.group(group)
    		 .channel(NioSocketChannel.class)
    		 .option(ChannelOption.TCP_NODELAY, true)
    		 .handler(new ClientInitializer());
            
            ChannelFuture channelFuture = gate.connect("127.0.0.1", 8888).sync();
            
            if(channelFuture.channel().isActive()){
           	sendMsg(channelFuture.channel());
            }
            channelFuture.addListener(new DisconnectListener()); //添加监听，处理重连
            channelFuture.channel().closeFuture().sync();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            group.shutdownGracefully();
        }
	}
	
	
	
	  public static void sendMsg(Channel channel) {
		   String str = "logon";
	       channel.writeAndFlush(str);
	   }
	  


	

}
